<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Cache;
use Auth;
use Hash;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function profile(Request $request)
    {
        return view('home.profile');
    }


    //每隔6十分钟校验安全码
    public function entryguard(Request $request)
    {
        // 如果认证记录 就返回上一级页面
        if (Cache::get(Auth::id() . '_guard')) {
            return back();
        }
        if ($request->isMethod('post')) {
            if (!Hash::check($request->password, Auth::user()->password)) {
                return ['message' => '安全密码不正确', 'status' => 2];
            }
            Cache::put(Auth::id() . '_guard', true, 60);

            return ['message' => session('url'), 'status' => 1];
        }
        return view('home.entryguard');
    }
}
